package cn.buk.tms.eotms.controller;

import cn.buk.common.JsonResult;
import cn.buk.common.dto.CommonDto;
import cn.buk.tms.eotms.dto.FlightRefundOrderRequestDto;
import cn.buk.tms.eotms.response.RefundOrderResponseDto;
import cn.buk.tms.eotms.sc.SearchFlightOrderCriteria;
import cn.buk.tms.eotms.service.RefundOrderService;
import cn.buk.tms.exception.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yfdai
 */
@RestController
@RequestMapping("/flight")
public class RefundOrderController extends BaseController {

  @Autowired
  private RefundOrderService refundOrderService;

  /**
   * 查找退票订单
   *
   * @return
   */
  @GetMapping("/refunds")
  public CommonDto<RefundOrderResponseDto> searchFlightRefundOrders(HttpServletRequest request,
      @ModelAttribute("sc") SearchFlightOrderCriteria sc) {

    List<RefundOrderResponseDto> tickets = refundOrderService.searchRefundOrders(getUserId(request), sc);

    CommonDto<RefundOrderResponseDto> commonDto = new CommonDto<>();
    commonDto.setDataList(tickets);
    commonDto.setPage(sc.getPage());

    return commonDto;
  }

  /**
   * 获取退票订单详情
   */
  @RequestMapping(value = "/refund/{id}", method = RequestMethod.GET)
  public RefundOrderResponseDto getFlightRefundOrderDetail(HttpServletRequest request,
                                                   @PathVariable("id") int id
  ) {
    return refundOrderService.getFlightRefundOrderDetail(getUserId(request), id);
  }

  /**
   * 创建机票退票订单(多人一起提交）
   */
  @RequestMapping(value = "/refund", consumes = "application/json", method = RequestMethod.POST)
  public JsonResult createFlightRefundOrderV2(HttpServletRequest request,
                                              @RequestBody FlightRefundOrderRequestDto dto) throws BaseException {

    return refundOrderService.createFlightRefundOrder(getUserId(request), dto);
  }
}
